package com.ethan.http;

import org.reactivestreams.Subscriber;

import io.reactivex.rxjava3.annotations.NonNull;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;

public class ApiFowable<T extends BaseBean> extends Observable {
    T result;

    public ApiFowable(T result) {
        this.result = result;
    }

    public static <T extends BaseBean> ApiFowable<T> creater(T result) {
        return new ApiFowable(result);
    }

    @Override
    protected void subscribeActual(@NonNull Observer observer) {
        if (result.c == ApiError.BUSINESS_NO_PERMISSION || result.c == ApiError.BUSINESS_SERVER_ERROR) {
            observer.onError(new ApiException(result.c, result.m));
        } else {
            observer.onNext(result);
        }
    }
}
